<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ include file="/common/index.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统用户</title>
<link type="text/css" rel="stylesheet" href="<%=basePath %>/css/index.css" />
<script language="javascript" src="<%=basePath %>/js/jquery-1.7.1.min.js"></script>
<script language="javascript" src="<%=basePath %>/js/lightbox/jquery.lightbox_me.js"></script>
<script language="javascript" src="<%=basePath %>/js/validate.js"></script>
<script language="javascript" src="<%=basePath %>/js/window_center.js"></script>
</head>
<body>
        <div class="right_main">
        	<div class="right_title">基础管理 >  开发者列表</div> 
            <div class="right_main_title_bg">
            	<s:form id="selectForm"  action="/manager/user/select.shtml" theme="simple">  
					<div class="right_main_padding_1">
						<span class="spanTxt">开发者账号：</span>
                      	<s:textfield  name="vo.devname" value="" theme="simple"  cssClass="inputText_1" maxlength= "20" /> 
	                    <span class="btn_1 searchBtn"  id="selectButton" onclick="selectData();" ></span>
	                    <span style="display: none"> 
							gotoPage<s:textfield name="gotoPage" id="gotoPage" /> 
							pageSize<s:textfield name="pageSize" id="pageSize" /> 
							firstPage<s:textfield name="firstPage" id="firstPage" /> 
							lastPage<s:textfield name="lastPage" id="lastPage" />
							nextPage<s:textfield name="nextPage" id="nextPage" />
							prePage<s:textfield name="prePage" id="prePage" /> 
							countPage<s:textfield name="countPage" id="countPage" />
							countData<s:textfield name="countData" id="countData" />
						</span>
                </div>
			    </s:form>
                <table class="table_1" cellpadding="0" cellspacing="1">
                	<tr class="th_bg">
                        <td>开发者账号</td>
                        <td>注册IP</td>
                        <td>注册时间</td>
                        <td>上次登陆时间</td>
                        <td>用户状态</td>
                        <td>账号类型</td>
                        <td>绑定手机号码</td>
                        <td>操作</td>
                    </tr>
                 <s:iterator value="devUserList" status="st">  
                 		<s:if test="#st.odd==true">
	                 		<tr class="tr_1">
	                 	</s:if>
	                 	<s:else>
	                 		<tr class="tr_2">
	                 	</s:else>
                        <td><s:property value="devname"/></td>
                        <td><s:property value="regip"/></td>
                       	<td><s:date name="createtime" /></td>
                       	<td><s:date name="logintime"/></td>
                        <td><s:if test="status==0">可用</s:if><s:else>禁用</s:else></td>
                        <td><s:property value="type"/></td>
                       	<td><s:property value="phonenum"/></td>
                       	<td>
                       		<s:if test="devname!='administrator'">
                       		<span class="shouxing" onclick="deleteVo('<s:property value="devid"/>')"> 删除</span>
                        	</s:if>
                       	</td>
                 	</tr>
				 </s:iterator>                    
                </table>
                <div class="page_div">
                    共 <span id="allcount"><s:property value="countData"/></span> 条记录 &nbsp;	每页 <span id="pagesize" ><s:property value="pageSize"/></span> 条记录&nbsp;
					共 <span id="pagecount" ><s:property value="countPage"/></span> 页&nbsp;
					第 <span id="pageno" ><s:property value="gotoPage"/></span> 页&nbsp;&nbsp;
					<input type="button" class="wbt" value="首页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('firstPage').value;selectData();}else{alert('已经在首页');}"/>
					&nbsp;
					<input type="button" class="wbt" value="上一页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('prePage').value;selectData();}else{alert('已经在首页');}" />
					&nbsp;
					<input type="button" class="wbt" value="下一页" onclick="if(g('gotoPage').value != g('countPage').value){g('gotoPage').value=g('nextPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;
					<input type="button" class="wbt" value="末页" onclick="if(g('gotoPage').value != g('lastPage').value){g('gotoPage').value=g('lastPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;&nbsp;
                    
            	</div>
            </div>
        </div>

<div id="SHOW_DIV_1" style="height:600px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title">编辑服务</div>
            <div class="content">
              <s:form id="insert-update-Form" name="insert-update-Form"  theme="simple">  
              	<input type="hidden" class="inputText_1" name="vo.id" id="vo.id"  />
              	<input type="hidden" class="inputText_1" name="vo.configJson" id="vo.configJson" />
                <ul>
                    <li>
                        <span class="spanTxt">服务名：</span>
                        <input type="text" class="inputText_1" name="vo.serverName" id="vo.serverName"  maxlength="20"  />
                        <span class="spanTxt">日志类型：</span>
                        <select name="vo.logType" id="vo.logType">
                        	<option value="debug">debug</option>
                        	<option value="info">info</option>
                        	<option value="warn">warn</option>
                        	<option value="error">error</option>
                        	<option value="fatal">fatal</option>
                        </select>
                    </li>
                    <li>
                        <span class="spanTxt">机房：</span>
                        <input type="text" class="inputText_1" name="vo.pcRoom" id="vo.pcRoom"  maxlength="15"  />
                         <span class="spanTxt">IP：</span>
                        <input type="text" class="inputText_1" name="vo.ip" id="vo.ip"  maxlength="15"  />
                    </li>
                    <li>
                        <span class="spanTxt">tcp_port：</span>
                        <input type="text" class="inputText_1" name="vo.tcpPort"  id="vo.tcpPort"   maxlength="8"  />
                        <span class="spanTxt">http_port：</span>
                        <input type="text" class="inputText_1" name="vo.httpPort"  id="vo.httpPort"  maxlength="8"  />
                    </li>
                    
                    <li>
	                    <span class="spanTxt">version：</span>
                        <input type="text" class="inputText_1" name="vo.version" maxlength="15"  />
                        <span class="spanTxt">备注：</span>
                        <input type="text" class="inputText_1" name="vo.remark" maxlength="15"  />
                    </li>
                    <li>
                    	<span class="spanTxt">&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        <span class="default_btn_2" name="add_but" id="add_but" >添加其他配置</span>
                    </li>
                </ul>
      			</s:form>
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="insert-update-but"  onclick="insert();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">取消</span>
            </div>
        </div>
	</div>
<script language="javascript">

	$(function(){
		
		$('#add_but').click(function(){
			var ___li = $('<li class="para_li"><span class="spanTxt">配置key：</span>&nbsp;<input type="text" class="inputText_1 _config_key" />  <span class="spanTxt">配置value：</span>&nbsp;<input type="text" class="inputText_1"  />  &nbsp;&nbsp;<span class="close_but shouxing" >X</span></li>');
			$('#add_but').parent().before(___li);  
		});
		
		
		$('.close_but').live('click',function(){
			$(this).parent().remove();
		});
		
		
		$('.showJson').live('click',function(){
			var json = eval( '(' + $(this).attr('configJson') + ')');
			showOtherConfig($(this).attr('strName'),json);				
		});
		
		
		$(".setDbFunc").live('click',function(){
			to_Set_DB($(this));
		});
		
		
	})


	 function selectData()
	 {	
	 	$("#selectForm").submit();
	 }

	function toInsertDiv(){
		$("#SHOW_DIV_1").lightbox_me({
			 centered: false
			,modalCSS:{}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
		$('#insert-update-but').attr("onclick","insert();");
	}
	
	function insert(){
		if(!checkParas()){
			return;
		}
		var url = "<%=basePath %>/manager/server/insert.shtml";
		document.getElementById("vo.configJson").value=getParaJsonData(); //jquery去查找节点，不能包含点号"."  quickExpr 
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}else{
						alert('操作失败');
					}
				}
		   ,'json');
		clearFormValue('insert-update-Form');
	}

	function toUpdateDiv(id){
		$("#SHOW_DIV_1").lightbox_me({
			centered: false
			,modalCSS:{top:'20px'}
			,onLoad:function(){
				var url = "<%=basePath %>/manager/server/selectVoById.shtml";
				var param = {id:id};
				$.post(url 
					,param 
						,function(rs) {
							if(rs.code==0){
								fillTemplateValue("insert-update-Form",rs.data);
								var json = eval( '(' + rs.data.configJson + ')');
								createJsonInput(json);
							}
						}
				   ,'json');
			}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
	}
	

	function update(){
		if(!checkParas()){
			return;
		}
		var url = "<%=basePath %>/manager/server/update.shtml";
		document.getElementById("vo.configJson").value=getParaJsonData(); //jquery去查找节点，不能包含点号"."  quickExpr 
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
		
		clearFormValue('insert-update-Form');
	}
	
	function checkParas(){
		if(document.getElementById("vo.serverName").value==''){
			alert('请输入服务名');	
			return false;
		}
		var reg =  /^\s{0,}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
		if(!reg.exec(document.getElementById("vo.ip").value)){
			alert('Ip格式错误');
			return false;
		}
		reg = /[0-9]{4,7}/;
		if(!reg.exec(document.getElementById("vo.tcpPort").value)){
			alert('tcpPort格式错误');
			return false;
		}
		if(!reg.exec(document.getElementById("vo.httpPort").value)){
			alert('httpPort格式错误');
			return false;
		}
		return true;
	}
	
	
	function fillTemplateValue(boxId,json){
		var keys = new Array("id","serverName","logType","pcRoom","ip","tcpPort","httpPort","version","remark"); //这个要自定义
		for(var i=0;i<keys.length;i++){
			var e1 = $("#insert-update-Form [name*="+keys[i]+"]");
			if(e1.prop("nodeName")=="TEXTAREA"){
				e1.html(json[keys[i]]);
			}else if(e1.prop("nodeName")=="INPUT" || e1.prop("nodeName")=="SELECT" ){
				e1.val(json[keys[i]]);
			}
		}
		$('#insert-update-but').attr("onclick","update();");
	}

	function clearFormValue(fId){
		$('#'+fId)[0].reset();
		$(".para_li").remove();
	}
	
	function deleteVo(id){
		var url = "<%=basePath %>/manager/user/delete.shtml";
		var param = {id:id};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}else{
						alert(rs.info);
					}
				}
		   ,'json');
	}


	function getParaJsonData(){
		var str = '';
	 	var isSuccess = false;
	 	$('._config_key').each(function(i) {
	 		isSuccess = false;
 			var temp = '"'+$(this).val()+'":"'+$(this).parent().find("input:last").val()+'"';
 			if(i==0){
 				str = str+temp;
 			}else{
 				str = str+','+temp;
 			}
 			isSuccess = true;
	 	});
	 	
	 	if(isSuccess){
			return '{'+str+'}';
	 	}else{
	 		return '';
	 	}
	}
	
	
	function createJsonInput(json){
		for(var o in json){
			var ___li = $('<li class="para_li"><span class="spanTxt">配置key：</span>&nbsp;<input type="text" class="inputText_1 _config_key"  value="'+o+'" /><span class="spanTxt">配置value：</span>&nbsp;<input type="text" class="inputText_1" value="'+json[o]+'" />  &nbsp;&nbsp;<span class="close_but shouxing">X</span></li>');
			$('#add_but').parent().before(___li);  
		}
	}
	
	
	function showOtherConfig(strName,json){
		$('.show_div_2_para_li').remove();
		$('#SHOW_DIV_2_title').html(strName+'-->其他配置');
		
		var b0 = true; //json是否为空
		
		for(var o in json){
			b0 = false;
			var ___li = $('<li class="show_div_2_para_li"><span class="spanTxt">配置key：</span>&nbsp;<input type="text" class="inputText_1"  value="'+o+'" /><span class="spanTxt">配置value：</span>&nbsp;<input type="text" class="inputText_1" value="'+json[o]+'" /> </li>');
			$('#add_otherconfig_but').parent().before(___li);  
		}
		
		if(b0){
			var ___li = $('<li class="show_div_2_para_li"><span class="spanTxt">-----暂无-----</span></li>');
			$('#add_otherconfig_but').parent().before(___li);
		}	
			  
		
		$("#SHOW_DIV_2").lightbox_me({
			 centered: false
			,modalCSS:{top:'30px'}
			,onClose:function(){}
		});
	}
	
	
	function to_Set_func(strName,pk){
		
		document.getElementById("sf.baseServer.id").value=pk;
		$('#SHOW_DIV_3_title').html(strName+'-->接口分配');
		$("#SHOW_DIV_3").lightbox_me({
			 centered: false
			,modalCSS:{top:'30px'}
			,onClose:function(){clearFormValue('set-func-Form');}
		});
	}
	
	
	function set_func(){
	
		if(document.getElementById("sf.function").value==''){
			alert('请输入接口名');
			return false;
		}
	
		var reg =  /^\s{0,}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
		if(!reg.exec(document.getElementById("sf.receiver").value)){
			alert('访问者Ip格式错误');
			return false;
		}
		
		var url = "<%=basePath %>/manager/server/set_func.shtml";
		var pk = document.getElementById("sf.baseServer.id").value;
		
		var param = $("#set-func-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						clearFormValue('set-func-Form');
						document.getElementById("sf.baseServer.id").value=pk;
						alert('操作成功,请去服务接口列表查看');
					}else{
						alert('操作失败');
					}
				}
		   ,'json');
	}
	
	
	function to_Set_DB(obj){
		
		$("input[name=server_db_ref]").attr("checked",false);
				
		var db_ids = new Array();  
		
		obj.parent().parent().find("input[name='___hidden_db']").each(function(i){
		   db_ids.push($(this).val());
		});
		
		setCheckBoxValue(db_ids,'server_db_ref');
		
		document.getElementById("server_db_ref_id").value=obj.attr('___id');
		$('#SHOW_DIV_4_title').html(obj.attr('___serverName')+'-->DB设置');
		$("#SHOW_DIV_4").lightbox_me({
			 centered: false
			,modalCSS:{top:'30px'}
			,onClose:function(){clearFormValue('set-db-Form');}
		});
	}
	
	
	function set_DB(){
		var url = "<%=basePath %>/manager/server/set_db.shtml";
		var pk =  document.getElementById("server_db_ref_id").value;
		var param = {'id':pk,'dbIds':getCheckBoxValue("server_db_ref")};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						alert('操作成功');
						selectData();
					}else{
						alert('操作失败');
					}
				}
		   ,'json');
	}
	
	
	function getCheckBoxValue(para) {
    	var str = "";
    	$("input[name*="+para+"]:checked").each(function(index) {
   			str += $(this).val()+',';
    	});
    	
    	if(str.lastIndexOf(',')==str.length-1){
				str = str.substring(0,(str.length-1));
		}
    	
		return str;    
    }
    
    
    function setCheckBoxValue(array,checkName) {
		$.each(array, function(i, n){
			 $("input:checkbox[name='"+checkName+"'][value='"+n+"']").attr('checked','true');
		});
    }
    
	
	function goDbPage(str){
		window.parent.openMainFrame('<%=basePath %>/manager/db/select.shtml?vo.dbName='+str,'a2');
	}
	
	function gofuncPage(pk){
		window.parent.openMainFrame('<%=basePath %>/manager/server/selectFunc.shtml?sf.baseServer.id='+pk,'a1');
	}


</script>     
<div id="SHOW_DIV_2" style="height:600px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title" id="SHOW_DIV_2_title"></div>
            <div class="content">
                <ul>
                    <li>
                    	<span class="spanTxt">&nbsp;&nbsp;&nbsp;&nbsp;</span>
                        <span id="add_otherconfig_but" ></span>
                    </li>
                </ul>
            </div>
            <div class="bottom">
                <span class="default_btn_1 close">关闭</span>
            </div>
        </div>
</div>      
<div id="SHOW_DIV_3" style="height:600px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title" id="SHOW_DIV_3_title"></div>
            <div class="content">
            <s:form id="set-func-Form" name="set-func-Form"  theme="simple">  
            <input type="hidden" class="inputText_1" name="sf.baseServer.id" id="sf.baseServer.id"  />
                <ul>
                    <li>
	                    <span class="spanTxt">接口名<br>(如:getinfo)：</span>
                        <input type="text" class="inputText_1" name="sf.function" id="sf.function" maxlength="15"  />
                        <span class="spanTxt">访问者<br>(如:192.168.1.1)：</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" class="inputText_1" name="sf.receiver" id="sf.receiver" maxlength="15"  />
                    </li>
                </ul>
            </s:form>    
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="set_func_but"  onclick="set_func();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">关闭</span>
            </div>
        </div>
</div> 

<div id="SHOW_DIV_4" style="height:600px;display:none;overflow:auto;">
        <div class="show_main">
            <div class="title" id="SHOW_DIV_4_title"></div>
            <div class="content">
            <s:form id="set-db-Form" name="set-db-Form"  theme="simple">  
            <input type="hidden" class="inputText_1" name="server_db_ref_id" id="server_db_ref_id"  />
                <ul>
                   <s:iterator value="#session.allDbList" status="st">    
                   <li>
	                    <input type="checkbox"  name="server_db_ref"  value="<s:property value="id"/>" />
	                    <s:property  value="dbName"/>
                	</li>
                   </s:iterator> 
                </ul>
            </s:form>    
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="set_func_but"  onclick="set_DB();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">关闭</span>
            </div>
        </div>
</div> 
</body>
</html>
